package KK
{
	import KK.Cache.CacheManager;
	import KK.Data.Config;
	import KK.Data.GameData;
	import KK.EMVC.Control.Control;
	import KK.Event.GameSystemEvent;
	import KK.GameBase.IMessageQueue;
	import KK.GameBase.MSGEvent;
	import KK.Global.Game;
	import KK.Manager.IManager;
	import KK.System.ApplicationManager;
	import KK.Tip.GlobalTip;
	import KK.View.UIManager;
	import KK.View.Window.MessageBox;
	import KK.net.Proxy.ErrorProxy;
	import KK.net.Proxy.LoginProxy;
	import KK.net.Proxy.UserProxy;
	import KK.net.ProxyManager;
	import KK.net.ResourceManager;
	
	import flash.display.BitmapData;
	
	public class MainHandler extends Control
	{
		
		private var list:Vector.<IManager>;
		public function MainHandler()
		{
			//TODO: implement function
			super();
			init();
		}
		private function init():void{
			list=new Vector.<IManager>;
			ResourceManager.Start();
			
			RegisterManager();
		}
		
		
		
		
		
		
		override public function BindEvent(_event:IMessageQueue):Boolean{
			super.BindEvent(_event);
			initEvent();
			return true;
		}

		
		
		
		/**
		 * 娉ㄥ唽
		 * 
		 * @param manager    manager
		 */
		public function Register(manager:Class):void{
			list.push(new manager);
			//			list[list.length-1].Run();
		}
		
		
		
		
		/**
		 *  
		 * 
		 */
		private function RegisterManager():void{
			
			
			Register(UIManager);
			Register(Battle);
			list.push(GlobalTip.Instance);
		}
		
		
		/**
		 * 鍒濆鍖栦簨浠?
		 */
		private function initEvent():void{
			AttentionMessage(GameSystemEvent.RESOURCE_LOADED,onLoaded);
		}
		
		/**
		 * 鍔犺浇瀹屾瘯
		 * 
		 * @param event
		 */
		private function onLoaded(event:MSGEvent):void{
			//数据加载完毕 
			initConnect();
			initManager();
			initUI();
			 
			var obj:*=Config.CF_Face;
			LogInfo(obj);
		} 
		 
		
		/**
		 * 初始化ui 
		 * 
		 */
		private function initUI():void{
//			var windowSkin:BitmapData=CacheManager.GetCache("Window1").bitmapData;
//			var window:MessageBox=new MessageBox();
//			GameData.Word.addChild(window.GetMC());
//			window.Skin=windowSkin;
//			window.setSize(300,300);
//			window.Hide();
//			
//			window.ShowText("<font color='#FFFFFF'>faewfewa</font>");
			
			GameData.Word.stage.addChild(GlobalTip.Instance);
//			GlobalTip.Instance.ShowMsg("你有新消息. ");
			
			Game.ButtonTip(GameData.Word.stage,"静音按钮.");
		}
		
		/**
		 * 鍒濆鍖栫鐞嗙被
		 */
		private function initManager():void{
			var obj:IManager;
			for each(obj in list){
				obj.Run();
			}
		}
		
		/**
		 * 鍒濆鍖栬繛鎺?
		 */
		private function initConnect():void{
			
			Game.network.connect(Game.LoginAddress);
//			Game.network.TestConnect("192.168.1.117:10000");
		}
	}
}